{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/custom-sort-string\n",
    "\n",
    "\n",
    "Runtime: 0 ms, faster than 100.00% of C++ online submissions for Custom Sort String.\n",
    "Memory Usage: 6.2 MB, less than 87.06% of C++ online submissions for Custom Sort String.\n",
    "\n",
    "\n",
    "```cpp\n",
    "#include <vector>\n",
    "#include <algorithm>\n",
    "#include <iostream>\n",
    "#include <map>\n",
    "\n",
    "using namespace std;\n",
    "\n",
    "class Solution\n",
    "{\n",
    "public:\n",
    "    string customSortString(string S, string T)\n",
    "    {\n",
    "        //6:34\n",
    "        map<char, int> d;\n",
    "        for (int i = 0; i < T.size(); i++)\n",
    "        {\n",
    "            char c = T[i];\n",
    "            if (d.find(c) != d.end())\n",
    "            {\n",
    "                d[c] += 1;\n",
    "            }\n",
    "            else\n",
    "            {\n",
    "                d[c] = 1;\n",
    "            }\n",
    "        }\n",
    "        string r = \"\";\n",
    "        for (int i = 0; i < S.size(); i++)\n",
    "        {\n",
    "            char c = S[i];\n",
    "            if (d.find(c) != d.end())\n",
    "            {\n",
    "                for (int j = 0; j < d[c]; j++)\n",
    "                {\n",
    "                    r += c;\n",
    "                }\n",
    "                d.erase(d.find(c));\n",
    "            }\n",
    "        }\n",
    "\n",
    "        for (auto const &x : d)\n",
    "        {\n",
    "\n",
    "            for (int j = 0; j < x.second; j++)\n",
    "            {\n",
    "                r += x.first;\n",
    "            }\n",
    "        }\n",
    "\n",
    "        return r;\n",
    "        //6:44\n",
    "    }\n",
    "};\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "C++17",
   "language": "C++17",
   "name": "xcpp17"
  },
  "language_info": {
   "codemirror_mode": "text/x-c++src",
   "file_extension": ".cpp",
   "mimetype": "text/x-c++src",
   "name": "c++",
   "version": "17"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
